package com.xinnet.mms.member.service.impl;

import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xinnet.core.utils.ConfigUtil;
import com.xinnet.mms.entity.Customer;
import com.xinnet.mms.member.dao.MemberDao;
import com.xinnet.mms.member.service.MemberService;
/**
 * 
 * @author 王湛智
 *
 */
@Service("memberService")
public class MemberServiceImpl implements MemberService {
	
	@Autowired
	private MemberDao memberDao;
	//private SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	/**
	 * 获取某个时间区间的所有会员
	 */
	@Override
	public List<Customer> getMemberByTimeSet(String timeSet) throws Exception {
//		Calendar calendar=Calendar.getInstance();
//		Date nowDate=new Date();
//		calendar.setTime(nowDate);
//		calendar.add(Calendar.MINUTE, -timeSet);
//		nowDate=calendar.getTime();
//		calendar.add(Calendar.MINUTE, -timeSet);
		Customer customer=new Customer();
		customer.setTimeStamp(timeSet);
		customer.setTimeStampLimit(Integer.parseInt(ConfigUtil.getString("TIMESTAMPLIMIT")));
		return memberDao.getTimeSetMember(customer);
	}
	
	/**
	 * 根据会员ID查询会员详细信息
	 */
	@Override
	public Customer getMemberByCusId(String cusId) throws SQLException {
		return memberDao.getMemberByCusId(cusId);
	}

	/**
	 * 获取limit区间所有会员
	 */
	@Override
	public List<Customer> getMemberByLimit(Integer top, Integer down) throws Exception {
		Customer customer=new Customer();
		customer.setLimitTop(top);
		customer.setLimitDown(down);
		List<Customer> list=memberDao.getMemberByLimit(customer);
		if(list==null || list.isEmpty()) {
			return null;
		}
		else {
			return list;
		}
	}

	/**
	 * 获取会员总记录数
	 */
	@Override
	public Integer getAllMemberCount() throws SQLException {
		return memberDao.getAllMemberCount();
	}

}
